package com.example.demo.mapper;

import com.example.demo.entity.CultureBackgroundCollection;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CultureBackgroundCollectionMapper {
    // 添加文化背景收藏
    @Insert("INSERT INTO culture_background_collection_tb (user_id, culture_background_detail_id, collection_date) " +
            "VALUES (#{user_id}, #{culture_background_detail_id}, #{collection_date})")
    int addCollection(CultureBackgroundCollection cultureBackgroundCollection);

    // 删除文化背景收藏
    @Delete("DELETE FROM culture_background_collection_tb WHERE user_id = #{user_id} AND culture_background_detail_id = #{culture_background_detail_id}")
    int deleteCollection(@Param("user_id") Integer userId, @Param("culture_background_detail_id") Integer cultureBackgroundDetailId);

    // 修改Mapper层：查询用户收藏的所有文化背景信息
    @Select("SELECT c.*, cb.title AS title, cb.type AS type, cb.image AS image " +
            "FROM culture_background_collection_tb c " +
            "JOIN culture_background_detail_tb cb ON c.culture_background_detail_id = cb.culture_background_detail_id " +
            "WHERE c.user_id = #{user_id}")
    List<CultureBackgroundCollection> getCollectionsByUserId(@Param("user_id") Integer userId);

    // 检查用户是否收藏某个文化背景
    @Select("SELECT COUNT(*) FROM culture_background_collection_tb WHERE user_id = #{user_id} AND culture_background_detail_id = #{culture_background_detail_id}")
    int checkIfCollected(@Param("user_id") Integer userId, @Param("culture_background_detail_id") Integer cultureBackgroundDetailId);
}
